package com.hp.bon.sgw.threads;

import java.util.concurrent.ConcurrentHashMap;

import com.hp.bon.sgw.bean.CapabilityLifeBean;

public class CapabilityLifeManager{
	private ConcurrentHashMap<String,Boolean> capStatusMap = new ConcurrentHashMap<String, Boolean>();
	private static CapabilityLifeManager instance = null;
	
	private CapabilityLifeManager(){}
	
	public static CapabilityLifeManager getInstance(){
		if(instance == null){
			instance = new CapabilityLifeManager();
		}
		return instance;
	}

	/**
	 * @param hostId
	 * @param serviceContextId
	 * @return
	 */
	public boolean checkActive(String hostId, String serviceContextId){
		String key = CapabilityLifeBean.getLifeKey(hostId, serviceContextId);
		if(!capStatusMap.containsKey(key)){
			return true;
		}
		return capStatusMap.get(key);
	}
	
	public void refresh(ConcurrentHashMap<String,Boolean> capStatusMapNew){
		for (String key : capStatusMap.keySet()) {
			if(!capStatusMapNew.containsKey(key)){
				capStatusMap.remove(key);
			}
		}
		capStatusMap.putAll(capStatusMapNew);
	}
}
